<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <ul id="box"></ul>
    <!--  -->
    <script>
      var obj = {
        name: '小王',
        age: 18,
        sex: '男'
      }
      // 1 .Object.keys()   把对象key 获取为数组
      console.log(Object.keys(obj)) //["name", "age", "sex"]
      //判断数组为空
      // if(arr.length==0){}
      //判断对象为空
      // if(Object.keys(obj).length==0){}

      // 2.Object.values()   把对象key 获取为数组
      console.log(Object.values(obj)) //["小王", "18", "男"]
      // 3. Object.entries() 获取对象的key，value   [[key1,value1],[key2,value2]]
      console.log(Object.entries(obj))
      var arr = Object.entries(obj)
      var box = document.getElementById('box')
      var str = ``
      for (let k of arr) {
        str += `<li>${k[0]}---${k[1]}</li>`
      }
      box.innerHTML = str
    </script>
  </body>
</html>
